package chapter11;

public abstract class Event implements Comparable<Event>{
	protected long delayTime;
	protected long eventTime;
	public Event(long delayTime)
	{
		this.delayTime=delayTime;
		start();
	}
	
	public void start()
	{
		this.eventTime=System.nanoTime()+this.delayTime;
	}
	
	public boolean ready()
	{
		long now=System.nanoTime();
		System.out.println("now:"+now+" eventtime:"+this.eventTime);
		return now>=this.eventTime;
	}
	public abstract void action();
	
	public long getDelayTime()
	{
		return delayTime;
	}
	@Override
	public int compareTo(Event o) {
		// TODO Auto-generated method stub
		if(this.delayTime>o.delayTime)
			return 1;
		else if(this.delayTime==o.delayTime)
			return 0;
		return -1;
	}
	

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub

	}

}
